<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>关于this</title>
  </head>
  <body>
    <!-- <script>
      function fruit_shop() {
        console.log(this); // 打印？
        function eat_watermelon() {
          console.log("I eat watermelon.", this); // 打印？
        }
        eat_watermelon();
      }
      const fruit_shop_bind = fruit_shop.bind({});
      fruit_shop_bind();
      fruit_shop.apply({});
      fruit_shop.call({});
    </script>
    <script>
      function FruitShop() {
        console.log(this); // 打印？
        function eat_grape() {
          console.log("I eat grape.", this); // 打印？
        }
        eat_grape();
      }
      new FruitShop();
    </script>
    <script>
      function fruit_shop() {
        console.log(this); // 打印？
        function eat_grape() {
          console.log("I eat grape.", this); // 打印？
        }
        eat_grape();
      }
      fruit_shop();
    </script> -->
    <!-- <script>
      /**
       * 写出所有的打印结果
       */
      function revoke() {
        console.log(this);
      }
      function eat_plum() {
        console.log(this);
        revoke();
      }
      eat_plum(); // 第一处
      const fruit_shop = {
        name: "Welcome to 1 of Xiao Wu Fruit Shop.",
        eat_plum,
        eat_watermelon() {
          console.log(this);
          revoke();
        },
      };
      fruit_shop.eat_plum(); // 第二处
      fruit_shop.eat_watermelon();// 第三处
      const eat_fresh_plum = fruit_shop.eat_plum;
      eat_fresh_plum(); // 第四处
      console.log(eat_fresh_plum === eat_plum); // 第五处
      const eat_fresh_watermelon = fruit_shop.eat_watermelon;
      eat_fresh_watermelon();// 第六处
    </script> -->
    <!-- <script>
      Object.prototype.eat = function () {
        console.log(this.name);
      };
      function eat_fresh() {
        console.log(this.name);
      }
      const peach = {
        name: "peach",
        eat_fresh,
      };  
      const fruits = {
        name: "fruit",
        peach,
      };
      fruits.peach.eat();
      fruits.peach.eat_fresh();
    </script> -->
    <!-- <script>
      function eat_plum() {
        console.log(this);
      }
      function repetition(fn) {
        fn();
      }
      const fruit = {
        name: "fruit",
        eat_plum,
      };
      repetition(fruit.eat_plum); // ?
    </script> -->
    <!-- <script>
      "use strict"
      function FruitShop() {
        console.log(this); // 打印？
        function eat_grape() {
          console.log("I eat grape.", this); // 打印？
        }
        eat_grape();
      }
      new FruitShop();
    </script> -->
    <!-- <script>
      function fruit_shop() {
        console.log(this); // 打印？
        const eat_watermelon = () => {
          console.log("I eat watermelon.", this); // 打印？
        };
        eat_watermelon();
      }
      const fruit_shop_bind = fruit_shop.bind({});
      fruit_shop_bind();
      fruit_shop.apply({});
      fruit_shop.call({});
    </script> -->
    <!-- <script>
      function foo() {
        console.log(this.a);
      }

      var a = 2;
      var o = { a: 3, foo: foo };
      var p = { a: 4 };

      o.foo(); // ?
      (p.foo = o.foo)(); // ?
      p.foo(); // ?
    </script> -->
    <!-- <script>
      var shop_name = "welcome to 1 of Xiao Wu Fruit Shop.";
      const fruit_shop_name = () => {
        console.log(this.shop_name);
      };
      const fruit_shop = {
        shop_name: "welcome to 2 of Xiao Wu Fruit Shop.",
      };
      const bind = fruit_shop_name.bind(fruit_shop);
      bind();
    </script> -->
    <!-- <script>
      function foo() {
        return () => {
          console.log(this.a);
        };
      }

      const obj1 = {
        a: 2,
      };

      const obj2 = {
        a: 3,
      };

      const bar = foo.call(obj1);
      bar.call(obj2); 
    </script> -->
    <!-- <script>
      function eat() {
        console.log(this.name);
      }
      const peach = {
        name: "peach",
      };
      const plum = {
        name: "plum",
      };
      eat.call(peach);
      eat.call(plum);
    </script> -->
    <!-- <script>
      function fruit_shop() {
        console.log(this);
      }
      (function () {
        "use strict";
        fruit_shop(); // window
      })();
    </script> -->
    <!-- <script>
      function fruit_shop_eat() {
        console.log(this);
        function eat_plum() {
          console.log(this);
        }
        eat_plum();
      }
      const fruit_shop = {
        name: "welcome to 1 of xiao wu fruit shop",
      };
      fruit_shop_eat.call(fruit_shop); // fruit_shop  window
    </script> -->
    <!-- <script>
      const fruit_shop_eat = () => {
        console.log(this);
        const eat_plum = () => {
          console.log(this);
        };
        eat_plum();
      };
      const fruit_shop = {
        name: "welcome to 1 of xiao wu fruit shop",
      };
      fruit_shop_eat.call(fruit_shop); // window  window
    </script> -->
    <!-- 
    <script>
      function fruit_shop_eat() {
        console.log(this);
        return () => {
          console.log(this);
        };
      }
      const fruit_shop = {
        name: "welcome to 1 of xiao wu fruit shop",
      };
      const eat = fruit_shop_eat.call(fruit_shop); // fruit_shop
      eat(); // fruit_shop
    </script> -->
    <!-- <script>
      function eat() {
        console.log(this.name);
      }
      const peach = {
        name: "peach",
        eat,
      };
      peach.eat(); // peach
    </script> -->
    <!-- <script>
       function eat() {
        console.log(this.name);
      }
      const peach = {
        name: "peach",
        eat,
      };
      const eat_fresh = peach.eat;
      eat_fresh(); // ""
      console.log(eat_fresh === eat); // true
      console.log(peach.eat === eat); // true
    </script> -->
    <!-- <script>
      const fruit_shop = () => {
        console.log(this);
      };
      const fruit_shop_bind = fruit_shop.bind({});
      fruit_shop_bind(); // {}
      fruit_shop.apply({}); // {}
      fruit_shop.call({}); // {}
    </script> -->

    <script>
      "use strict"
      const fruit_shop = () => {
        console.log(this);
      };
      fruit_shop(); // window

    </script>
  </body>
</html>
